/***************************************************************************
 *   Copyright (C) 2007 by vasaka,,,   *
 *   gorinich.zmey at gmail   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 3 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/

#ifndef RANDOZAVR_H_
#define RANDOZAVR_H_

#include <math.h>
#include <vector>

using namespace std;

//class which generates set of unic random elements of type T
template < class T >
class Randozavr
{
public:
  Randozavr(unsigned int N_El) : SizeOfSet_m(N_El)
  {
    RndVector_m.resize(SizeOfSet_m); for (unsigned int i=0;i<SizeOfSet_m;i++) RndVector_m[i]=i; //start with ordered array
  };
  T operator[] (unsigned int index) {return RndVector_m[index];}
  void RandomizeN (unsigned int N)
  {
    if (N > SizeOfSet_m) N = SizeOfSet_m;
    for (unsigned int i=0;i<N;i++)
    {
      T temp = RndVector_m[i];
      T rndPlace = rand()%SizeOfSet_m;
      RndVector_m[i] = RndVector_m[rndPlace];
      RndVector_m[rndPlace] = temp;
    }
  }
protected:
  vector< T > RndVector_m; //actual vector with random numbers
  unsigned int SizeOfSet_m;
};

#endif /*RANDOZAVR_H_*/
